<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.pay.sdk.*"%>
<%@ page import="java.text.*"%>
<%@ page import="com.pay.sdk.service.channel2.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.alibaba.fastjson.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>支付宝即时到账交易接口</title>
</head>
<%
	////////////////////////////////////请求参数//////////////////////////////////////

	//商户订单号
	String out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"), "UTF-8") != null
			? new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"), "UTF-8")
			: new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
	//付款金额
	String total_fee = new String(request.getParameter("total_fee").getBytes("ISO-8859-1"), "UTF-8"); //单位分
	String body = new String(request.getParameter("body").getBytes("ISO-8859-1"), "UTF-8");
	String device_info = "wap";
	String time_expire = "1440";
	String acquirer_type = "alipay";
	String bank_card_limit = "2";//支付卡类型：1-储蓄卡 2储蓄卡和信用卡
	//服务器异步通知页面路径
	String notify_url = new String(request.getParameter("notify_url").getBytes("ISO-8859-1"), "UTF-8");
	String attach = "sOpenId=2831486693613247347563";

	//////////////////////////////////////////////////////////////////////////////////

	String result = ChanneTwolPay.scanPay(out_trade_no, total_fee, body, device_info, notify_url, acquirer_type,
			bank_card_limit, time_expire, attach);

	JSONObject jsonObj = JSONObject.parseObject(result);
	String status = jsonObj.getString("status");
	String message = jsonObj.getString("message");
	String err_msg = jsonObj.getString("err_msg");
	String code_url = jsonObj.getString("code_url");
	if ("0".equals(status)) {
		if ("success".equals(message)) {
			response.sendRedirect(code_url);
			out.print(result);
		} else {
			out.print("<script>alert('" + err_msg + "');</script>");
			out.print(result);
		}
	} else {
		out.print(result);
		out.print("<script>alert('" + message + "');</script>");
	}
%>
<body>
</body>
</html>
